<?php

class Autoload
{
    /**
     * namespace alias
     * @var array
     */
    public static $alias = array();

    /**
     * root path
     * @var string
     */
    public static $directory;

    /**
     * autoload functin
     * @param  string $class namespace
     * @return [type]        [description]
     * @author marvin
     * @date   2016-03-21
     */
    public static function load($class)
    {
        $namespace = str_replace(array('\\', '_'), DS, ltrim($class, '\\'));
        $lower = strtolower($namespace);

        if (array_key_exists($namespace, self::$alias)) {
            return class_alias(self::$alias[$namespace], $namespace);
        }
        if (is_file(self::$directory . $namespace . '.php')) {
            return require self::$directory . $namespace . '.php';
        }
        if (is_file(self::$directory . $lower . '.php')) {
            return require self::$directory . $lower . '.php';
        }

        return false;
    }
}